'use strict';
module.exports = {
	/**
	 * XXXnameXXX
	 * @url agent/callback/pub/tengxun 前端调用的url参数地址
	 * data 请求参数
	 * @param {String} params1  参数1
	 */
	main: async (event) => {
		let {
			data = {}, userInfo, util, filterResponse, originalParam
		} = event;
		let {
			customUtil,
			uniID,
			config,
			pubFun,
			vk,
			db,
			_
		} = util;
		let {
			uid,
			pt,
			account_id,
			click_id,
			click_time,
			device_os_type,
			ip,
			user_agent,
			callback,
			ad_id,
			tfid,
			invite_code,
			wechat_openid
		} = data;
		let res = {
			code: 0,
			msg: ""
		};
		// 业务逻辑开始-----------------------------------------------------------
		// let request_id = vk.pubfn.getUniCloudRequestId();
		// let look_log = await db.collection('vk-test').add({
		// 	tips: "查看腾讯触点信息日志云函数",
		// 	request_id: request_id,
		// })
		var time = new Date().getTime()
		//记录广告平台发过来的触点信息，并保存到数据库，以备后面流程调用
		let addchudian = await db.collection('jl_chudian').add({
			pt: pt || "tengxun", //平台（快手/抖音/其他等等）
			tfid: tfid || 0,
			invite_code: invite_code || 0,
			ts: click_time, //客户端发生广告点击事件的时间，以毫秒为单位时间戳
			wechat_openid: wechat_openid, //用户客户端IP
			aid: ad_id, //创意id
			useid: account_id, //广告主id
			os: device_os_type, //操作系统平台
			ua: user_agent, //用户代理(User Agent)
			callback_url: callback, //
			callback: click_id, //其他平台clickid都是callback,腾讯平台需保持一致
			time: time,
			time_str: vk.pubfn.timeFormat(new Date(), "yyyy-MM-dd hh:mm:ss")
		})
		console.log("addchudian=", addchudian);

		// 业务逻辑结束-----------------------------------------------------------
		return res;
	}
}